package IAPractica1;

import java.util.ArrayList;
import java.util.List;

import IA.Gasolina.Distribucion;
import IA.Gasolina.Gasolinera;
import aima.search.framework.Successor;
import aima.search.framework.SuccessorFunction;
import aima.util.Pair;

public class IAPrac1GenerarSuccessors implements SuccessorFunction {
	
	
	public List getSuccessors(Object aState) {
		
		IAPrac1Representacio repr = (IAPrac1Representacio) aState;
		ArrayList successors = new ArrayList();		
		IAPrac1FuncioHeuristica1 heuristica =  new IAPrac1FuncioHeuristica1(); 
		
		//Para cada asignacion hacemos swap con todas las demas asignaciones
		int numAssig = repr.size();
		for (int i = 0; i < numAssig; i++){
			
			for (int j = i+1; j < numAssig; j++){
				
				
				IAPrac1Representacio newRepr = new IAPrac1Representacio();
				newRepr.setAssignacions(repr.getAssignacions());
				newRepr.setEstado(repr.getEstado());
				
				boolean restricciones = comprobarRestricciones(i,j,newRepr);
				if (restricciones){
					newRepr.swap(i, j);			
				
					double v = heuristica.getHeuristicValue(newRepr);
					
					int idGas1 = newRepr.getGasAsociadas().get(i);
					int idGas2 = newRepr.getGasAsociadas().get(j);
					
					String S = IAPrac1Representacio.SWAP +" (Peticion: "+i+ " gasolinera: "+idGas1+") (Peticion: "+j+" gasolinera: "+idGas2+" "+" Coste("+v+") ---> " + newRepr.toString();
							
					successors.add(new Successor(S, newRepr));
				}
				
			}			
		}			
		
		return successors;
	}

	private boolean comprobarRestricciones(int i, int j, Object aState) {
		// TODO Auto-generated method stub
		return true;
	}	
}
